import { uIsFindColors, uFindColorsClick } from '../utils'
export default class {
  /* Holo  配置文件
    options = {
      config,
      count,
    }
  */
  constructor(cRepeatMap) {
    this.cRepeatMap = cRepeatMap
    this.count = null
  }

  //  * 初始化的时候调用一次
  init(count) {
    count ? this.count = count : this.count = 999
    let i = 0;

    while (i < this.count) {
      this.blueClick()

      if (this.san()) break;
      this.redClick()
      console.show()
      log('开始第' + (++i) + '次刷图！')

      sleep(15000)

      while (true) {
        this.costOnlyClick()
        sleep(2000)

        if (uIsFindColors([this.cRepeatMap.blue], 0)) {
          console.hide()
          log('第' + i + '次刷图完成')
          break;
        }
      }

    }
  }

  //  * 点击蓝色开始按钮
  blueClick() {
    return uFindColorsClick([this.cRepeatMap.blue], 0)
  }

  // * 点击红色开始按钮
  redClick() {
    return uFindColorsClick([this.cRepeatMap.red], 0)
  }

  // *  判断理智是否为0
  san() {
    const { san } = this.cRepeatMap
    sleep(1000);
    const is = uIsFindColors([san.point, san.relative], 0);

    if (is) click(san.point.x, san.point.y)
    return is;
  }

  // * 点击 cost 位置
  costOnlyClick() {
    const { cost } = this.cRepeatMap
    click(cost.x, cost.y)
  }
}
